package com.example.daxiguaforharmony.game.system;

import com.example.daxiguaforharmony.game.Fruits;
import com.example.daxiguaforharmony.game.GameData;
import com.example.daxiguaforharmony.game.GameScene;
import com.example.daxiguaforharmony.game.core.featrue.IReactiveSystem;

public class UseDiceSystem implements IReactiveSystem {
    private GameScene _scene = null;
    public boolean enabled = true;
    public UseDiceSystem(GameScene scene) {
        this._scene = scene;
    }

    @Override
    public boolean Filter(String type) {
        return this.enabled && type == GameScene.Event.USE_DICE_ITEM;
    }

    @Override
    public void Execute(String type, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) {
        boolean ret = this.genNextGameObject();
        if (ret == false) {
            String msg = "此道具，只能在水果下落之前使用！";
            this._scene.showToast(msg);
            return;
        }
        GameData gameData = this._scene.gameData;
        gameData.addItemNum(GameScene.ItemID.ITEM2, -1);
        this._scene.AddEvent(GameScene.Event.USE_ITEM, GameScene.ItemID.ITEM2, 1, null, null);
    }

    @Override
    public void Destory() {}

    public boolean genNextGameObject() {
        Fruits fruits = this._scene.getCurrFruits();
        if (fruits == null) return false;
        if (fruits.getTag() != 10000) return false;
        fruits.killTween();
        this._scene.pushInFruitsPool(fruits);
        this._scene.createNextFruits();
        return true;
    }
}
